<?php

class TableSQL extends RootClass {
	
	private $SQL;
	private $columns;

	// Constructor class
	function __construct() {
		$this->columns = array();
		$this->SQL = null;
	}
	
	function addColumn($NAME,$LABEL=null) {
		if($LABEL == null)
			$LABEL=$NAME;
		$this->columns[count($this->columns)] = array($NAME,$LABEL);
	}
	
	function setSQL($SQL) {
		$this->SQL = $SQL;
	}
	
	function show() {
		HTML_TABLE("ALIGN=CENTER");
		HTML_TR_S();
		for($i=0;$i<count($this->columns);$i++) {
			$TEXT = $this->columns[$i][1];
			
			// $TEXT .= "<IMG SRC=\"../img/arrow_up.png\" border=0>";
			// $TEXT .= "<IMG SRC=\"../img/arrow_down.png\" border=0>";
			
			HTML_TH($TEXT);
		}
		HTML_TR_F();
		
		global $db;
		if($RESULTS = $db->get_results($this->SQL,ARRAY_N)) {
			foreach($RESULTS as $ROW) {
				HTML_TR_S();
				for($i=0;$i<count($ROW);$i++) {
					HTML_TD($ROW[$i]);
				}
				HTML_TR_F();
			}
		}
		else {
			HTML_TD("Nenhum registro cadastrado.","COLSPAN=".count($this->columns));
		}
		HTML_TABLE_F();
	}
}
?>